Extending linear regression to model a continuous outcome using multiple predictor variables.
General Principles
To study relationships between multiple continuous independent variables (e.g., the effect of weight and age on height), we can use a multiple regression approach. Essentially, we extend Linear Regression for continuous variable by adding a regression coefficient \beta_x for each continuous variable (e.g., \beta_{weight} and \beta_{age}).
The model interpretation of the regression coefficients \beta_x is considered for fixed values of the other independent variable(s)’ regression coefficients—i.e., for a given age, \beta_{weight} represents the expected change in the dependent variable (height) for each one-unit increase in weight, holding all other variables (e.g., age) constant.
Example
Below is example code demonstrating Bayesian multiple linear regression using the BayesForge (BF) package. Data consist of three continuous variables (height, weight, age), and the goal is to estimate the effect of weight and age on height. This example is based on McElreath (2018).
We model the relationship between the independent variables (X_{1i}, X_{2i}, ..., X_{[K,i]}) and the dependent variable Y using the following equation:
X_{[1,i]}, X_{[2,i]}, …, X_{[K,i]} are the values of the independent variables for observation i.
\beta_1, \beta_2, …, \beta_K are the regression coefficients.
\epsilon_i is the error term for observation i, and the vector of the error terms, \epsilon, are assumed to be independent and identically distributed.
Bayesian formulation
In the Bayesian formulation, we define each parameter with priors 🛈. We can express the Bayesian model as follows:
\alpha is the intercept term, with a Normal(178, 20) prior centred on a plausible adult height (height is not scaled).
\beta_k are slope coefficients for the K distinct independent variables, with Normal(0, 0.5) priors (the predictors are scaled).
X_{[1,i]}, X_{[2,i]}, …, X_{[K,i]} are the values of the independent variables for observation i.
\sigma is a standard deviation parameter, which here has a Uniform prior that constrains it to be positive.
Model validation tests
Comparison with Stan: 1b.Multiple continuous variables.py fits the same model with BayesForge and Stan and compares the posterior distributions (KL divergence) and parameter recovery.
Data generative model and inference model pipeline: 1b.Multiple continuous variables.py simulates data from the model with known parameters (data generative model), fits the inference model to each simulated dataset and checks that the parameters are recovered.